package com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.bo.ITXingzhengshouwenNeirongBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.vo.TXingzhengshouwenNeirong;
import com.tjsinfo.tjsoa.workflow.WorkFlowTemplate;



/**
 * 行政收文管理查询发文
 * @author Administrator
 *
 */
public class AdminselectAction extends Action{
	private ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO;
	
	


	public ITXingzhengshouwenNeirongBO getXingzhengshouwenNeirongBO() {
		return xingzhengshouwenNeirongBO;
	}




	public void setXingzhengshouwenNeirongBO(
			ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO) {
		this.xingzhengshouwenNeirongBO = xingzhengshouwenNeirongBO;
	}




	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		List<TXingzhengshouwenNeirong> list;
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (request.getParameter("start") == null) {
			list =  xingzhengshouwenNeirongBO.selectXingzhengshouwenPage(0, 23,request.getParameter("laiwenjihuan"),request.getParameter("laiwenzihao"),request.getParameter("zhaiyao"));
		} else {
			Integer first = Integer.parseInt(request.getParameter("start"));
			list = xingzhengshouwenNeirongBO.selectXingzhengshouwenPage(first, 23,request.getParameter("laiwenjihuan"),request.getParameter("laiwenzihao"),request.getParameter("zhaiyao"));
		}
		Integer totalProperty = xingzhengshouwenNeirongBO.selectXingzhengshouwenTotalLine(request.getParameter("laiwenjihuan"),request.getParameter("laiwenzihao"),request.getParameter("zhaiyao"));
		object.put("totalProperty", totalProperty);
		for (TXingzhengshouwenNeirong xingzhengshouwenNeirong : list) {
			JSONObject shouwenJSON = new JSONObject();
			if (workFlowTemplate.isEnd(Long.parseLong(xingzhengshouwenNeirong.getFlowid().toString()) )) {
				shouwenJSON.put("state", "是");
				shouwenJSON.put("laiwenzihao", xingzhengshouwenNeirong.getLaiwenzihao());
				shouwenJSON.put("laiwenjihuan", xingzhengshouwenNeirong.getLaiwenjiguan());
				shouwenJSON.put("zongshouwenhao", xingzhengshouwenNeirong.getShouwenbianhao());
				shouwenJSON.put("zhaiyao", xingzhengshouwenNeirong.getZhaiyou());
				shouwenJSON.put("shouwenriqi", ToolKit.FormatDate(xingzhengshouwenNeirong.getLaiwenriqi()));
				shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+xingzhengshouwenNeirong.getFlowid()+
						"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=adminselectonedoc&id="+xingzhengshouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;<a href='"+basePath+"documentationflow/xingzhengshouwen/yanzhenglist.jsp?id="+xingzhengshouwenNeirong.getId()+"'>验证列表</a>"
						+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=guidangform&id="+xingzhengshouwenNeirong.getId()+"'>归档</a>");
				if(xingzhengshouwenNeirong.getIsguidang() != null){
					shouwenJSON.put("state", "归档");
				}
				array.put(shouwenJSON);
			}
			else  if (workFlowTemplate.isSuspend(Long.parseLong(xingzhengshouwenNeirong.getFlowid().toString()) )) {
				shouwenJSON.put("state", "中止");
				shouwenJSON.put("laiwenzihao", xingzhengshouwenNeirong.getLaiwenzihao());
				shouwenJSON.put("laiwenjihuan", xingzhengshouwenNeirong.getLaiwenjiguan());
				shouwenJSON.put("zongshouwenhao", xingzhengshouwenNeirong.getShouwenbianhao());
				shouwenJSON.put("zhaiyao", xingzhengshouwenNeirong.getZhaiyou());
				shouwenJSON.put("shouwenriqi", ToolKit.FormatDate(xingzhengshouwenNeirong.getLaiwenriqi()));
				if("登记修改".equals(workFlowTemplate.selectNodeName(Long.valueOf(xingzhengshouwenNeirong.getFlowid().toString())))){
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+xingzhengshouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=adminselectonedoc&id="+xingzhengshouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:resume("+xingzhengshouwenNeirong.getFlowid()+")'>重启</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+xingzhengshouwenNeirong.getId()+"'>修改</a>&nbsp;&nbsp;"+"<a href='javascript:deleteprocess(\""+xingzhengshouwenNeirong.getId()+"\")'>删除流程</a>"+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+xingzhengshouwenNeirong.getId()+"'>修改附件</a>");
				}else{
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+xingzhengshouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=adminselectonedoc&id="+xingzhengshouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:resume("+xingzhengshouwenNeirong.getFlowid()+")'>重启</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+xingzhengshouwenNeirong.getId()+"'>修改</a>"+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+xingzhengshouwenNeirong.getId()+"'>修改附件</a>");
				}
				if(xingzhengshouwenNeirong.getIsguidang() != null){
					shouwenJSON.put("state", "归档");
				}
				array.put(shouwenJSON);
			}
			else {
				shouwenJSON.put("state", "否");
				shouwenJSON.put("laiwenzihao", xingzhengshouwenNeirong.getLaiwenzihao());
				shouwenJSON.put("laiwenjihuan", xingzhengshouwenNeirong.getLaiwenjiguan());
				shouwenJSON.put("zongshouwenhao", xingzhengshouwenNeirong.getShouwenbianhao());
				shouwenJSON.put("zhaiyao", xingzhengshouwenNeirong.getZhaiyou());
				shouwenJSON.put("shouwenriqi", ToolKit.FormatDate(xingzhengshouwenNeirong.getLaiwenriqi()));
				if("登记修改".equals(workFlowTemplate.selectNodeName(Long.valueOf(xingzhengshouwenNeirong.getFlowid().toString())))){
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+xingzhengshouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=adminselectonedoc&id="+xingzhengshouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:suspend("+xingzhengshouwenNeirong.getFlowid()+")'>中止</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+xingzhengshouwenNeirong.getId()+"'>修改</a>&nbsp;&nbsp;"+"<a href='javascript:deleteprocess(\""+xingzhengshouwenNeirong.getId()+"\")'>删除流程</a>"
							+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+xingzhengshouwenNeirong.getId()+"'>修改附件</a>"
							+"&nbsp;&nbsp;<a href='javascript:cuiban(\""+xingzhengshouwenNeirong.getId()+"\")'>催办</a>"+"&nbsp;&nbsp;<a href='javascript:end("+xingzhengshouwenNeirong.getFlowid()+")'>完结</a>");
				}else{
					shouwenJSON.put("operate", "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+xingzhengshouwenNeirong.getFlowid()+
							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=adminselectonedoc&id="+xingzhengshouwenNeirong.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:suspend("+xingzhengshouwenNeirong.getFlowid()+")'>中止</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+xingzhengshouwenNeirong.getId()+"'>修改</a>"+
							"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+xingzhengshouwenNeirong.getId()+"'>修改附件</a>"
							+"&nbsp;&nbsp;<a href='javascript:cuiban(\""+xingzhengshouwenNeirong.getId()+"\")'>催办</a>"+"&nbsp;&nbsp;<a href='javascript:end("+xingzhengshouwenNeirong.getFlowid()+")'>完结</a>");
				}
				if(xingzhengshouwenNeirong.getIsguidang() != null){
					shouwenJSON.put("state", "归档");
				}
				array.put(shouwenJSON);
			}
		
		}
		request.getSession().setAttribute("xingzhengshouadminliststart", Integer.parseInt(request.getParameter("start")));
		object.put("root", array);
		response.getWriter().print(object);
		return null;
	}
	
}
